package com.accloud.cloudservice;

import com.accloud.common.ACConfiguration;
import com.accloud.service.ACAQI;
import com.accloud.service.ACException;
import com.accloud.service.ACMsg;
import com.accloud.service.ACObject;
import com.accloud.service.ACPM25;
import com.accloud.service.ACWeather;
import com.accloud.service.ACWeatherMgr;
import java.util.ArrayList;
import java.util.List;

public class ACWeatherManager extends ACBaseManager implements ACWeatherMgr {
    public ACWeatherManager() {
        super(ACConfiguration.PM25_SERVICE_NAME, 1, false);
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLatestPM25(String area, final PayloadCallback<ACPM25> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLatestPM25Data");
        req.put("area", area);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass1 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACPM25(resp.getString("timestamp"), resp.getInt("value"), resp.getInt("min"), resp.getInt("max")));
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLastDaysPM25(String area, int day, final PayloadCallback<List<ACPM25>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLastDaysPM25Data");
        req.put("area", area);
        req.put("days", Integer.valueOf(day));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass2 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objectList = resp.getList("history");
                ArrayList arrayList = new ArrayList();
                for (ACObject object : objectList) {
                    arrayList.add(new ACPM25(object.getString("timestamp"), object.getInt("value"), object.getInt("min"), object.getInt("max")));
                }
                callback.success(arrayList);
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLastHoursPM25(String area, int hour, final PayloadCallback<List<ACPM25>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLastHoursPM25Data");
        req.put("area", area);
        req.put("hours", Integer.valueOf(hour));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass3 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objectList = resp.getList("history");
                ArrayList arrayList = new ArrayList();
                for (ACObject object : objectList) {
                    arrayList.add(new ACPM25(object.getString("timestamp"), object.getInt("value"), object.getInt("min"), object.getInt("max")));
                }
                callback.success(arrayList);
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLatestAqi(String area, final PayloadCallback<ACAQI> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLatestAqi");
        req.put("area", area);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass4 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACAQI(resp.getInt("aqi"), resp.getInt("min"), resp.getInt("max"), resp.getString("timestamp")));
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLastDaysAqi(String area, int day, final PayloadCallback<List<ACAQI>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLastDaysAqi");
        req.put("area", area);
        req.put("days", Integer.valueOf(day));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass5 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objectList = resp.getList("history");
                ArrayList arrayList = new ArrayList();
                for (ACObject object : objectList) {
                    arrayList.add(new ACAQI(object.getInt("aqi"), object.getInt("min"), object.getInt("max"), object.getString("timestamp")));
                }
                callback.success(arrayList);
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLastHoursAqi(String area, int hour, final PayloadCallback<List<ACAQI>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLastHoursAqi");
        req.put("area", area);
        req.put("hours", Integer.valueOf(hour));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass6 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objectList = resp.getList("history");
                ArrayList arrayList = new ArrayList();
                for (ACObject object : objectList) {
                    arrayList.add(new ACAQI(object.getInt("aqi"), object.getInt("min"), object.getInt("max"), object.getString("timestamp")));
                }
                callback.success(arrayList);
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLatestWeather(String area, final PayloadCallback<ACWeather> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLatestWeatherData");
        req.put("area", area);
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass7 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                callback.success(new ACWeather(resp.getString("timestamp"), resp.getDouble("temperature"), resp.getDouble("minTemperature"), resp.getDouble("maxTemperature"), resp.getInt("humidity"), resp.getInt("minHumidity"), resp.getInt("maxHumidity")));
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLastDaysWeather(String area, int day, final PayloadCallback<List<ACWeather>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLastDaysWeatherData");
        req.put("area", area);
        req.put("days", Integer.valueOf(day));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass8 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objectList = resp.getList("history");
                ArrayList arrayList = new ArrayList();
                for (ACObject object : objectList) {
                    arrayList.add(new ACWeather(object.getString("timestamp"), object.getDouble("temperature"), object.getDouble("minTemperature"), object.getDouble("maxTemperature"), object.getInt("humidity"), object.getInt("minHumidity"), object.getInt("maxHumidity")));
                }
                callback.success(arrayList);
            }
        });
    }

    @Override // com.accloud.service.ACWeatherMgr
    public void getLastHoursWeather(String area, int hour, final PayloadCallback<List<ACWeather>> callback) {
        if (!AC.accountMgr().isLogin()) {
            callback.error(new ACException(ACException.NO_LOGIN, "no login"));
            return;
        }
        ACMsg req = ACMsg.getACMsg(null);
        req.setName("getLastHoursWeatherData");
        req.put("area", area);
        req.put("hours", Integer.valueOf(hour));
        sendReq(req, callback, new ACMsgListener() {
            /* class com.accloud.cloudservice.ACWeatherManager.AnonymousClass9 */

            @Override // com.accloud.cloudservice.ACMsgListener
            public void finish(ACMsg resp) {
                List<ACObject> objectList = resp.getList("history");
                ArrayList arrayList = new ArrayList();
                for (ACObject object : objectList) {
                    arrayList.add(new ACWeather(object.getString("timestamp"), object.getDouble("temperature"), object.getDouble("minTemperature"), object.getDouble("maxTemperature"), object.getInt("humidity"), object.getInt("minHumidity"), object.getInt("maxHumidity")));
                }
                callback.success(arrayList);
            }
        });
    }
}
